GtkSidebar: Pick up the visible child from the stack
authorMatthias Clasen <mclasen@redhat.com>
Tue, 7 Oct 2014 03:06:54 +0000 (23:06 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 7 Oct 2014 03:07:35 +0000 (23:07 -0400)
Same here: We need to synchronize the visible child with the
selected row when setting a stack on the sidebar. I've noticed
this problem in the sidebar example in gtk3-widget-factory.

gtk/gtksidebar.c

index 7e9fe6f35c9fcb7482f52b6831654a0f1c1dc81c..7ccc5218a8ec6bee47582e716ab197d1c2174339 100644 (file)
@@ -327,8 +327,16 @@ static void
 populate_sidebar (GtkSidebar *sidebar)
 {
   GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
+  GtkWidget *widget, *row;
 
   gtk_container_foreach (GTK_CONTAINER (priv->stack), (GtkCallback)add_child, sidebar);
+
+  widget = gtk_stack_get_visible_child (priv->stack);
+  if (widget)
+    {
+      row = g_hash_table_lookup (priv->rows, widget);
+      gtk_list_box_select_row (priv->list, GTK_LIST_BOX_ROW (row));
+    }
 }
 
 static void